

package Order;

import DAO.DAO;
import DTO.Item;
import DTO.Order;
import Exception.KwickKioskDBException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * this class implements  the operations for order management in {@link IOrderManager} interface .
 * order management services are implemented in this class
 * @author tejinder
 * @see Order
 */
public class OrderManager implements IOrderManager {

    private DAO dao;
    
    /**
     * parameterized constructor
     * @param dao
     */
    public OrderManager(DAO dao) {
        this.dao =  dao;
    }

     /**
     * this method retrieves order history for a customer
     * @param csid an integer
     * @return an order data transfer object
     */
    
    public List<Order> getOrderHistory(Integer csid) {

        List<Order> ordersList =  new ArrayList<Order>();
        try {
            //get order list from dao
            // add to list and return
            ordersList = dao.getCustomerOrder(csid);
        } catch (KwickKioskDBException ex) {
            Logger.getLogger(OrderManager.class.getName()).log(Level.SEVERE, null, ex);
        }
       return ordersList;        
    }

    /**
     * this method inserts  an order into database
     * @param order data transfer object
     * @return an integer order id
     */
    
     public Integer makeDesktopOrder(Order order){
        //boolean success = true;
         Integer oid = null;
        try {
            oid = dao.makeDesktopOrder(order);
            System.out.println("order id is  "+oid);
        } catch (KwickKioskDBException ex) {
            //success = false;
            Logger.getLogger(OrderManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        return oid;
    }

    /**
     * this method retrieves item history for an order id
     * @param oid an integer
     * @return an item data transfer object
     */
    public List<Item> getItemHistory(Integer oid) {

        List<Item> itemList =  new ArrayList<Item>();
       try {
            //itemList = null;
           itemList = dao.getItemByOrder(oid);
       } catch (KwickKioskDBException ex) {
            Logger.getLogger(OrderManager.class.getName()).log(Level.SEVERE, null, ex);
        }

       return itemList;
    }

}
